package com.cjjd.c.feature.home.chekin.confirm_order;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.cjjd.c.R;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.BindInt;
import butterknife.ButterKnife;


/**
 * ----------------------------------
 * Created by xyd on 2017/8/30.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class ConfirmOrderExpandableListAdapter extends BaseExpandableListAdapter {

    private ArrayList<String> dataI;
    private ArrayList<ArrayList<String>> dataG;
    private Context mContext;

    public ConfirmOrderExpandableListAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getGroupCount() {
        return dataI.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
//        return dataG.get(groupPosition).size();
        return 1;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return dataI.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return dataG.get(groupPosition).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

        ViewHolderGroup viewHolderGroup = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.group_confirm_order, parent, false);
            viewHolderGroup = new ViewHolderGroup(convertView);
            convertView.setTag(viewHolderGroup);
        } else {
            viewHolderGroup = (ViewHolderGroup) convertView.getTag();
        }

        viewHolderGroup.tvCheckinName.setText(dataI.get(groupPosition));

        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ViewHolderChild viewHolderChild = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_confirm_order, parent, false);
            viewHolderChild = new ViewHolderChild(convertView);
            convertView.setTag(viewHolderChild);
        } else {
            viewHolderChild = (ViewHolderChild) convertView.getTag();
        }
        viewHolderChild.tvOrderForm.setText(dataG.get(groupPosition).get(0));
        viewHolderChild.tvPhone.setText(dataG.get(groupPosition).get(1));
        viewHolderChild.tvRoomMoney.setText(dataG.get(groupPosition).get(2));
        viewHolderChild.tvDepositMoney.setText(dataG.get(groupPosition).get(3));
        viewHolderChild.zongfangjia.setText(dataG.get(groupPosition).get(4));
        viewHolderChild.tvSpecialDemand.setText(dataG.get(groupPosition).get(5));
        viewHolderChild.tvReceiptNeed.setText(dataG.get(groupPosition).get(6));
        viewHolderChild.tvPayMode.setText(dataG.get(groupPosition).get(7));



        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }


    public void setGroupData(ArrayList<ArrayList<String>> listG) {
        this.dataG = listG;
    }

    public void setGroupTittleData(ArrayList<String> listI) {
        this.dataI = listI;
    }



    static class ViewHolderChild {
        @Bind(R.id.tv_order_form)
        TextView tvOrderForm;
        @Bind(R.id.tv_room_num)
        TextView tvRoomNum;
        @Bind(R.id.tv_order_person_name)
        TextView tvOrderPersonName;
        @Bind(R.id.tv_phone)
        TextView tvPhone;
        @Bind(R.id.tv_roomMoney)
        TextView tvRoomMoney;
        @Bind(R.id.tv_depositMoney)
        TextView tvDepositMoney;
        @Bind(R.id.tv_specialDemand)
        TextView tvSpecialDemand;
        @Bind(R.id.tv_receipt_need)
        TextView tvReceiptNeed;
        @Bind(R.id.tv_pay_mode)
        TextView tvPayMode;
        @Bind(R.id.zongfangjia)
        TextView zongfangjia;

        ViewHolderChild(View view) {
            ButterKnife.bind(this, view);
        }
    }

    static class ViewHolderGroup {
        @Bind(R.id.tv_checkin_title)
        TextView tvCheckinTitle;
        @Bind(R.id.tv_checkin_name)
        TextView tvCheckinName;

        ViewHolderGroup(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
